package com.hadoop.temperature;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class Sort extends WritableComparator {

	public Sort() {
		super(KeyPair.class, true);
	}

	@Override
	public int compare(WritableComparable a, WritableComparable b) {
		KeyPair k1 = (KeyPair) a;
		KeyPair k2 = (KeyPair) b;

		// Integer.compare默认是升序
		int ret = Integer.compare(k1.getYear(), k2.getYear());
		if (ret != 0) {
			return ret;
		}
		// 温度降序排序
		return Integer.compare(k2.getTemperature(), k1.getTemperature());
	}
}
